﻿/*-----------------------------------------------
// File: CopySmallBalance.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UI;

namespace Battle
{
    public class CopySmallBalance : MonoBehaviour
    {
        public UIGrid dropGrid;
        public UIScrollView scrollView;
        public GameObject iconPrefab;

        protected List<GameObject> dropItems = new List<GameObject>();
        public void Init() {
            foreach (var obj in dropItems)
                Destroy(obj);
            dropItems.Clear();
            var msg = StaticData.lastBattleEndMsg as ProtoBuf.Message.SCCopyFightEnd;
            foreach (var info in msg.currentResource)
            {
                var obj = GameObject.Instantiate(iconPrefab) as GameObject;
                obj.GetComponent<CommonIcon>().SetData(info.id, false, info.num);
                obj.transform.SetParent(dropGrid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                obj.transform.localEulerAngles = Vector3.zero;
                dropItems.Add(obj);
            }

            dropGrid.Reposition();
            scrollView.ResetPosition();
            
        }

        public void OnConfirmButtonClick() {
            Exit();
        }


        void Exit()
        {
            gameObject.SetActive(false);
            //ManagerController.Instance.BattleToCopy();
            Destroy(gameObject);
            Resources.UnloadUnusedAssets();
        }

        public UITweener posScale; 

        public virtual void PlayAni()
        {
            posScale.enabled = true;
            posScale.ResetToBeginning();
            posScale.PlayForward();
        }
    }
}
